#include <stdio.h>
#include <string.h>

void my_qsort(void *base, size_t num, size_t size, int (*compar)(const void *, const void *)) {
    //趟数
    for (int i = 0; i < num - 1; i++) {
        //一趟排序
        for (int j = 0; j < num - i - 1; j++) {
            //交换
            if (compar(base + j * size, base + (j + 1) * size) > 0) {
                char *address1 = (base + j * size);
                char *address2 = (base + (j + 1) * size);
                //按字节交换
                for (int k = 0; k < size; k++, address1++, address2++) {
                    char tmp = *address1;
                    *address1 = *address2;
                    *address2 = tmp;
                }
            }
        }
    }
}

int compar(const void *x, const void *y) {
    return *(int *) y - *(int *) x;
}

int main() {
    int arr[10] = {1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 10000};
    my_qsort(arr, 10, sizeof(arr[0]), compar);
    for (int i = 0; i < 10; i++)
        printf("%d ", arr[i]);
    return 0;
}




